home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12805 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: newsfeeds.ans.net!btco!newsadm
  2. From: Shalom Reich <sqr1874@acf4.nyu.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ questions - please help
  5. Date: Thu, 21 Mar 1996 14:12:22 -0500
  6. Organization: Bankers Trust Company
  7. Message-ID: <3151AA16.EAB@acf4.nyu.edu>
  8. References: <4irp34$b6q@GRAPEVINE.LCS.MIT.EDU>
  9. NNTP-Posting-Host: algsvw0058.btco.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (WinNT; I)
  14.  
  15. Frank Kim wrote:
  16. > Question #1:
  17. >   [snip]
  18. > and its constructor looks like this:
  19. > faxRmApp::faxRmApp() : request("remove") {}
  20. > I don't understand why the request("remove") initialization is outside
  21. > the brackets.
  22.  
  23. All initialization of member data and/or base classes for constructors should
  24. be done in the initialization list (between the ":" after the end of the parm list
  25. and before the "{" of the function body) instead of inside the function body.
  26. This is usually done for performance purposes but there can be other reasons as 
  27. well (i.e. initializing a virtual base class, initializing a reference).  
  28.  
  29. (See C++ Primer by Lippman or Effective C++ by Scott Meyer.)
  30.  
  31. > Question #2
  32. > Why does the scope of the external declaration not extend beyond the
  33. > inner block?
  34.  
  35. The whole purpose of scope is to limit visibility of variables.  The extern
  36. has more to do with storage life time and location (i.e. static and allocated
  37. elsewhere).  The variable may have storage allocated to it but I may not want
  38. it to be changed just anywhere (possibly by accident).
  39.  
  40. > Question #3
  41. > Is there any difference between these two declarations?
  42. >    char *s1 = "hello";
  43. >    char s2[] = "hello";
  44.  
  45. I believe that the first one only allocates a pointer that is initialized to 
  46. the address of the first byte of the string "hello".  I believe that the second
  47. one allocates space for six chars and initializes them to the value "hello\0".
  48.  
  49. Shalom Reich
  50.